/**
 *	users流程模块接口
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framework.Module.system.users;


import com.framerock.baselib.CDate;
import com.framerock.baselib.Jiami;
import com.framerock.baselib.Rock;
import com.framework.ACore.Model;
import com.framework.Flow.FlowListener;

import java.util.Map;

public class FlowListenerusers extends FlowListener {


    public Map<String, String> onReplacers(Map<String, String> da, int lx) {
        da.remove("pass");
        da.remove("rand");
        return da;
    }

    public Map<String, String> onEditdatars(Map<String, String> da) {
        da.remove("pass");
        da.remove("rand");
        return da;
    }

    public Map<String, String> onSavebefore(Map<String, String> da, String mid, Boolean isadd)
    {
        Map<String, String> map = Rock.getMap();
        String pass = Rock.getMapString(da, "pass");
        if(isadd && Rock.isEmpt(pass))pass = "123456"; //默认密码
        String notsave = "",savefields="";
        if(!Rock.isEmpt(pass)){
            String rand = CDate.gettime();
            savefields = "pass="+ Jiami.md5(pass+rand) +",rand="+rand+"";
        }else{
            notsave   = "pass,rand";
        }
        map.put("savefields", savefields);
        map.put("notsave", notsave);
        return map;
    }

    @Override
    public void onSaveafter(Map<String, String> da, String mid, Boolean isadd) {
        String mobile = Rock.getMapString(da,"mobile");
        if(!Rock.isEmpt(mobile)){
            Model.get(this.nDb,"usera").update("`mobile`='"+mobile+"'", "`uid`="+mid+"");
        }
    }
}
